Skip to content

cdc: reject malformed input and roll back recoverable failures - #148

Open
stevephodgson wants to merge 4 commits into
mainfrom
cdc-input-hardening
Open

stevephodgson wants to merge 4 commits into
mainfrom
cdc-input-hardening

Conversation

@stevephodgson

@stevephodgson stevephodgson commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Harden CDC request, response and persisted-log handling.

  • Validate CDC requests before replicating them.
  • Account for the CDC log-entry header when enforcing replication limits.
  • Replace oversized shard responses with MALFORMED_RESPONSE.
  • Remove malformed LogsDB responses from the correct response batch.
  • Avoid sending CDC responses to a zero source port.
  • Validate persisted entry fields before allocating request and response vectors.
  • Roll back SoftUnlinkDirectory when an oversized STAT_DIRECTORY response cannot be replicated.

This PR should be reviewed patch by patch.

Safety

Valid requests, responses that fit within the replication limit, and successful transactions follow the existing paths. There are no wire-format or storage-format changes.

Malformed client requests are rejected before entering LogsDB. Malformed LogsDB responses are dropped. Successfully decoded internal response contract violations remain assertions.

Corrupt persisted metadata still stops CDC processing through BincodeException. The new checks stop before decoding an invalid boolean or allocating vectors from corrupt counts.

The only new rollback path handles an oversized STAT_DIRECTORY response during SoftUnlinkDirectory. At that point the source edge has been locked but no irreversible operation has occurred, so CDC unlocks it before returning MALFORMED_RESPONSE.

@stevephodgson
stevephodgson requested a review from mcrnic August 20, 2026 11:12
@stevephodgson
stevephodgson marked this pull request as draft September 4, 2026 10:06
Reject malformed CDC requests before they enter LogsDB or directory-lock
handling. Keep request-specific validation beside each state machine while
using a thin dispatcher at the network boundary.

Account for the fixed CDC log-entry header when deciding whether client
requests and shard responses fit a replication datagram. Replace oversized
shard responses with MALFORMED_RESPONSE and avoid sending responses to a zero
source port.
When a LogsDB response fails to unpack, remove the placeholder from the
responses vector. Popping the requests vector instead can underflow it and
leaves the malformed response in the batch.
Validate the CDC bootstrap flag and serialized request and response counts
before resizing their vectors. Corrupt RocksDB values could otherwise create
invalid bool representations or drive allocations from untrusted counts.

Raise BincodeException on corruption so CDC startup or log application still
stops rather than continuing with damaged TernFS metadata.
A STAT_DIRECTORY response can contain enough directory metadata to fit the shard transport but not a CDC LogsDB entry. The CDC replaces that response with MALFORMED_RESPONSE before replication.

Release the edge locked by SoftUnlinkDirectory before returning that transport error to the client. Other decoded shard errors and response-shape violations remain internal invariants.
@stevephodgson
stevephodgson marked this pull request as ready for review September 4, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant